<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <p>{{ count }}</p>
      <button @click="count++">btn</button>
      <child1></child1>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      const Child2 = {
        template: `
          <div>child2组件 - {{ count }}</div>
        `,
        // 注入，可以获取到父组件传来的内容
        inject: ["count"],
      };

      const Child1 = {
        template: `
          <div>child1组件 - <child2></child2></div>
        `,
        components: {
          Child2,
        },
      };

      new Vue({
        el: "#app",
        data: {
          count: 20,
        },
        // 依赖，向子孙组件传递的内容
        // 穿透式的传递
        // 它是没有响应式的(vue2)，vue3有了响应式
        provide() {
          return {
            count: this.count,
          };
        },
        components: {
          Child1,
        },
      });
    </script>
  </body>
</html>
